#include "Vector3.h"
#include <math.h>

Vector3::Vector3(void)
{
}

Vector3::Vector3( double x, double y, double z )
{
	this->x = x;
	this->y = y;
	this->z = z;
}

Vector3::Vector3( Vector3* v )
{
	x = v->x;
	y = v->y;
	z = v->z;
}
Vector3::~Vector3(void)
{
}

double Vector3::length()
{
	return sqrt(x * x + y * y + z * z);
}

double Vector3::lengthSquared()
{
	return x * x + y * y + z * z;
}

Vector3* Vector3::negate()
{
	x = -x;
	y = -y;
	z = -z;
	return this;
}

Vector3* Vector3::negate( Vector3* dest )
{
	dest->x = -x;
	dest->y = -y;
	dest->z = -z;
	return dest;
}

Vector3* Vector3::normalize()
{
	double in = 1.0 / sqrt(x * x + y * y + z * z);
	x *= in;
	y *= in;
	z *= in;
	return this;
}

Vector3* Vector3::normalize( Vector3* dest )
{
	double in = 1.0 / sqrt(x * x + y * y + z * z);
	dest->x = x * in;
	dest->y = y * in;
	dest->z = z * in;
	return dest;
}

Vector3* Vector3::set( double x, double y, double z )
{
	this->x = x;
	this->y = y;
	this->z = z;
	return this;
}

Vector3* Vector3::set( Vector3 v )
{
	x = v.x;
	y = v.y;
	z = v.z;
	return this;
}

Vector3* Vector3::add( Vector3 v1, Vector3 v2, Vector3* dest )
{
	dest->x = v1.x + v2.x;
	dest->y = v1.y + v2.y;
	dest->z = v1.z + v2.z;
	return dest;
}

Vector3* Vector3::sub( Vector3 v1, Vector3 v2, Vector3* dest )
{
	dest->x = v1.x - v2.x;
	dest->y = v1.y - v2.y;
	dest->z = v1.z - v2.z;
	return dest;
}

Vector3* Vector3::scale( Vector3 v, double s, Vector3* dest )
{
	dest->x = v.x * s;
	dest->y = v.y * s;
	dest->z = v.z * s;
	return dest;
}

Vector3* Vector3::scale( double s, Vector3 v, Vector3* dest )
{
	dest->x = s * v.x;
	dest->y = s * v.y;
	dest->z = s * v.z;
	return dest;
}

double Vector3::dot( Vector3 v1, Vector3 v2 )
{
	return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}

Vector3* Vector3::cross( Vector3 v1, Vector3 v2, Vector3* dest )
{
	dest->x = v1.y * v2.z - v1.z * v2.y;
	dest->y = v1.z * v2.x - v1.x * v2.z;
	dest->z = v1.x * v2.y - v1.y * v2.x;
	return dest;
}